
<template>
  <div>
    <van-nav-bar
      title="工单详情"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <div class="content">
      <van-cell-group>
        <van-field v-model="order.type" label="设备类型" readonly />
        <van-field v-model="order.status" label="工单状态" readonly />
        <van-field v-model="order.engineer_name" label="项目名称" readonly />
        <van-field v-model="order.device_name" label="设备名称" readonly />
        <template>
          <van-field
            v-if="order.bill_why != null"
            v-model="order.bill_why"
            label="申报原因"
            readonly
          />
          <van-field v-else value="暂无申报原因" label="申报原因" readonly />
        </template>

        <van-field name="image" label="申报图片">
          <template #input>
            <van-tag size="large" v-if="order.begin_photos.length == 0" id="tag"
              >暂无申报图片
            </van-tag>
            <van-tag v-else>
              <img :src="order.begin_photos[0]" class="pic" />
              <img :src="order.begin_photos[1]" class="pic" />
              <img :src="order.begin_photos[2]" class="pic" />
            </van-tag>
          </template>
        </van-field>
      </van-cell-group>

      <div style="margin-top: 20px">
        <van-button
          type="info"
          v-if="order.status == '待接单'"
          @click="toConfirmHandler"
          style="
            width: 100%;
            background-color: #f5a31f;
            border: 0;
            color: #6e4d40;
          "
          >确认接单</van-button
        ><span v-else></span>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/utils/request.js";
import { mapState } from "vuex";
import { Dialog, Notify } from "vant";
export default {
  data() {
    return {
      order: {},
    };
  },
  computed: {
    ...mapState("user", ["info"]),
  },
  methods: {
    // 确认接单按钮
    toConfirmHandler() {
      Dialog.confirm({
        title: "友情提示",
        message: "是否确认接单",
      }).then(() => {
        get("/workorder/takeOrder", {
          id: this.order.id,
          account_id: this.info.id,
        }).then((res) => {
          // 提示成功
          Notify({ type: "success", message: "接单成功" });
          // 跳转至我的工单
          this.$router.push({
            path: "/manager/order",
          });
        });
      });
    },
  },
  created() {
    this.order = this.$route.query;
  },
};
</script>
<style scoped>
.content {
  padding: 15px;
}
.pic {
  width: 80px;
  height: 80px;
  margin-right: 15px;
}
.too {
  padding-top: 20px;
  padding-bottom: 17px;
}
.van-field__body .van-tag--default {
  background-color: #fff;
  color: #323233;
}
#tag {
  margin-left: -8px;
  font-size: 14px;
}
</style>
